let http = require('http')

let server = http.createServer()

server.on('request', function(request,response){
    // console.log('接收到请求');
    /* 
    request事件处理函数的第2个参数是用于进行响应操作
    response.write('响应的内容')         响应数据
    response.end()                      结束响应
    response.setHeader(响应头名,值)      设置响应头(响应头的设置要在响应数据之前)
    response.statusCode = 状态码        用于设置状态码
    */

    response.statusCode = 401
    response.setHeader('content-type','text/plain;charset=utf-8')
    response.write('您好')
    response.end()
})

server.listen('4201', function(){
    console.log('http://127.0.0.1:4201');
})

/* 
小结：
    response.statusCode = 状态码
    response.setHeader('头名','值')
    response.write('数据')
    response.end()
*/